﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace OpenTasksBehaviorsLibrary
{
    public class OpenMediaPlayerTaskAction : TriggerAction<DependencyObject>
    {
        public static readonly DependencyProperty UrlProperty =
            DependencyProperty.Register(
                "Url",
                typeof(string),
                typeof(OpenMediaPlayerTaskAction),
                new PropertyMetadata(string.Empty));

        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(OpenMediaPlayerTaskAction.UrlProperty, value); }
        }

        protected override void Invoke(object parameter)
        {
            string url = string.Format(this.Url);
            Uri uri = new Uri(url);
            var task = new Microsoft.Phone.Tasks.MediaPlayerLauncher();
            task.Media = uri;
            task.Show();
        }
    }
}
